<?php




echo '{
	"success":true,
	"msg":"success",
	"posts": [ {title : "test1", date : "01/01/2012",  author :"Leonel", content:"<p style=\"text-align:center\">contenu de l article</p>"}, {title : "test2", date : "02/01/2012", author :"Carlos", content:"contenu de l article 2"}]
     }';
			
return 0;

//$callback = $_REQUEST['callback'];
//
//// Create the output object.
//$output = array('title' => 'Apple', 'content' => 'Banana');
//
////start output
//if ($callback) {
//    header('Content-Type: text/javascript');
//    echo $callback . '(' . json_encode($output) . ');';
//} else {
//    header('Content-Type: application/x-json');
//    echo json_encode($output);
//}

//
define('WP_USE_THEMES', false);
if ($_SERVER['SERVER_NAME'] == 'localhost') {
    require_once('../../djavupixel/wordpress/wp-blog-header.php');
} else {
    require_once('../../wp-blog-header.php');
}
//
$callback = $_REQUEST['callback'];
//
//// set header for json mime type
////header('Content-type: application/json;');
//
$posts = array();

$numberposts = 5;
$offset = (intval($_GET['page']) - 1) * $numberposts;

$num_posts = wp_count_posts('post');

//print_r($num_posts);

$num_pages = intval($num_posts->publish / $numberposts);
if ($num_posts->publish % $numberposts != 0) {
    $num_pages++;
}

if ($page <= $num_pages) {

    $args = array( 'numberposts' => $numberposts, 'offset'=> $offset );
    $myposts = get_posts( $args );

    foreach( $myposts as $post ) : setup_postdata($post);
        $posts[] = array(
            //'id' => $post->ID,
            'title' => $post->post_title,
            //'permalink' => $post->guid,
            'date' => str_replace("-", "/", substr($post->post_date, 0, 11)),
            //'author_id' => $post->post_author,
            'author' => get_userdata($post->post_author)->display_name
            //'content' => wpautop(strstr($post->post_content, '<!--more-->', true))
            //'content' => esc_html($post->post_content)
            //'content' => wpautop( str_replace(']]>', ']]&gt;', apply_filters('the_content', $post->post_content) ) )
        );
    endforeach;


    
    //echo (json_encode(array('posts' => $posts)) );
//    
//    //print_r($myposts);
}
//start output
if ($callback) {
    header('Content-Type: text/javascript');
    echo $callback . '(' . json_encode(array('posts' => $posts)) . ');';
} else {
    header('Content-Type: application/json');
    echo json_encode(array('posts' => $posts));
}
?>
